<?php
class CommentAction extends Action {

    public function _initialize() {
        $Config = A('Config');
        $Config->checkLogIn();
        $Config->checkUserLevel(array('1'));
    }
    
    public function index() {
        $Comment = M('Comment');
        $comment = $Comment->order(array('add_time' => 'desc', 'comment_id' => 'desc'))->select();
        $this->assign('comment', $comment);
        $this->display();
    }
    
    // 删除评论
    public function delete() {
        if (isset($_GET['id'])) {
            $id = (int) $_GET['id'];
            $Comment = M('Comment');
            
            if ($Comment->delete($id)) {
                $this->success('成功删除评论！');
            } else {
                $this->error('删除评论失败！');
            }
        }
    }
    
    public function verify() {
        if (isset($_GET['id'])) {
            $id = (int) $_GET['id'];
            $Comment = M('Comment');
            $Comment->comment_id = $id;
            $comment = $Comment->find($id);

            if ($Comment->status == 0) {
                $Comment->status = 1;
            } else {
                $Comment->status = 0;
            }
            
            if (false !== $Comment->save()) {
                $this->success('操作成功！');
            } else {
                $this->error('操作失败！');
            }
        }
    }
}
?>